<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    // 定义一个类 
    class Person {
        constructor(name, age) {
            console.log('父类构造方法')
            this.name = name 
            this.age = age 
        }
        getInfo() {
            return `姓名：${this.name},年龄：${this.age}`
        }
    }

    let person = new Person('Jack', 18)
    console.log(person)
    console.log(person.getInfo())
    let person2 = new Person('Rose', 19) 
    console.log(person.getInfo == person2.getInfo) // true 
    console.log('typeof person.getInfo: ', typeof person.getInfo) // function 

    // 使用extends关键字实现继承 
    class BlackPerson extends Person {
        constructor(name, age, height) {
            super(name, age)
            console.log('子类构造方法')
            this.height = height 
        }
    }
    let xiaohei = new BlackPerson('John', 20, 180)
    console.log(xiaohei) // {name: 'John', age: 20, height: 180} 
    console.log(xiaohei.getInfo())

</script>
</html>